#!/usr/bin/env python
# encoding: utf-8
 
from twill import *
import urllib2,re
import time
 
USERNAME = 'itaoran'
PASSWORD = 'itaoran'
 
 
def login():
    return '''
go http://login.sina.com.cn/hd/signin.php?entry=blog
showforms
fv 1 username %(username)s
fv 1 password %(password)s
showforms
submit 0
'''
 
def autopost():
    return '''
go http://bar.sina.com.cn/thread.php?tid=2153216615
showforms
fv 3 content "Love You!!"
fv 3 link http://static7.photo.sina.com.cn/middle/4c1a896fg5be157cb2406&000
fv 3 anonymous 0
submit
'''
def main():
    data = {'username':USERNAME,'password':PASSWORD}
    cmd=login()%data
    print cmd
    print execute_string(cmd)
    for i in range(30):
        print execute_string(autopost())
        time.sleep(5)
        
if __name__ == '__main__':
    import doctest
    # doctest.testmod()
    main()

	
		
